package pe.com.ValoracionVivienda.views;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;

import pe.com.ValoracionVivienda.views.entrenamiento.CompEntrenamientoPrincipal;
import pe.com.ValoracionVivienda.views.mantenimiento.CompMantenimientoPrincipal;
import pe.com.ValoracionVivienda.views.prediccion.CompPrediccionPrincipal;
import pe.com.ValoracionVivienda.views.seguridad.CompSeguridadPrincipal;

import org.eclipse.wb.swt.SWTResourceManager;

public class ShellPrincipal extends Shell {

	private Composite composite;
	
	/**
	 * Create the shell.
	 * @param display
	 */
	public ShellPrincipal(Display display) {
		super(display, SWT.CLOSE | SWT.MAX | SWT.TITLE);
		setLayout(new GridLayout(1, false));
		
		ToolBar toolBar = new ToolBar(this, SWT.FLAT | SWT.RIGHT);
		toolBar.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
		
		ToolItem tltmEntrenamiento = new ToolItem(toolBar, SWT.NONE);
		tltmEntrenamiento.setImage(SWTResourceManager.getImage(ShellPrincipal.class, "/pe/com/ValoracionVivienda/images/Training_small.png"));
		tltmEntrenamiento.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				LoadEntrenamiento();
			}
		});
		tltmEntrenamiento.setText("Entrenamiento");
		
		ToolItem tltmPrediccin = new ToolItem(toolBar, SWT.NONE);
		tltmPrediccin.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				LoadPrediccion();
			}
		});
		tltmPrediccin.setImage(SWTResourceManager.getImage(ShellPrincipal.class, "/pe/com/ValoracionVivienda/images/prediccion_small.png"));
		tltmPrediccin.setText("Predicci\u00F3n");
		
		ToolItem tltmMantenimiento = new ToolItem(toolBar, SWT.NONE);
		tltmMantenimiento.setImage(SWTResourceManager.getImage(ShellPrincipal.class, "/pe/com/ValoracionVivienda/images/mantenimiento_small.gif"));
		tltmMantenimiento.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				LoadMantenimiento();
			}
		});
		tltmMantenimiento.setText("Mantenimiento");
		
		ToolItem tltmSeguridad = new ToolItem(toolBar, SWT.NONE);
		tltmSeguridad.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				LoadSeguridad();
			}
		});
		tltmSeguridad.setImage(SWTResourceManager.getImage(ShellPrincipal.class, "/pe/com/ValoracionVivienda/images/seguridad_small.png"));
		tltmSeguridad.setText("Seguridad");
		
		composite = new Composite(this, SWT.NONE);
		composite.setLayout(new FillLayout(SWT.HORIZONTAL));
		composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		
		createContents();
		setMaximized(true);
	}

	protected void LoadSeguridad() {
		if (composite.getChildren().length > 0)
			composite.getChildren()[0].dispose();
		
		new CompSeguridadPrincipal(composite, SWT.NONE);
		composite.layout(true);
	}

	protected void LoadPrediccion() {
		if (composite.getChildren().length > 0)
			composite.getChildren()[0].dispose();
		
		CompPrediccionPrincipal comp = new CompPrediccionPrincipal(composite, SWT.NONE);
		comp.initData();
		composite.layout(true);
	}

	protected void LoadEntrenamiento() {
		if (composite.getChildren().length > 0)
			composite.getChildren()[0].dispose();
		
		CompEntrenamientoPrincipal comp = new CompEntrenamientoPrincipal(composite, SWT.NONE);
		comp.initData();
		composite.layout(true);
	}

	protected void LoadMantenimiento() {
		if (composite.getChildren().length > 0)
			composite.getChildren()[0].dispose();
		
		new CompMantenimientoPrincipal(composite, SWT.NONE);
		composite.layout(true);
	}

	/**
	 * Create contents of the shell.
	 */
	protected void createContents() {
		setText("SP3");
		setSize(587, 442);
		
	}

	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}
}
